//*********************************************************
//
//    Copyright (c) Microsoft. All rights reserved.
//    This code is licensed under the Apache License, Version 2.0.
//    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
//    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
//    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
//    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
//
//********************************************************* 

using System;
using System.Collections.Generic;
using System.Xml.Serialization;

namespace Microsoft.TridentWordAddIn.Common
{
    [XmlRoot("Workflow")]
    public class Workflow : DomainBase
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="Workflow"/> class.
        /// </summary>
        public Workflow()
        {
            this.Activities = new List<WorkflowActivity>();
            this.Parameters = new List<WorkflowParameter>();
        }

        /// <summary>
        /// Gets or sets the id.
        /// </summary>
        /// <value>The id.</value>
        [XmlElement("Id")]
        public Guid Id { get; set; }

        /// <summary>
        /// Gets or sets the name.
        /// </summary>
        /// <value>The name.</value>
        [XmlElement("Name")]
        public string Name { get; set; }

        /// <summary>
        /// Gets or sets the display name.
        /// </summary>
        /// <value>The display name.</value>        
        public string DisplayName { get; set; }

        /// <summary>
        /// Gets or sets the description.
        /// </summary>
        /// <value>The description.</value>
        public string Description { get; set; }

        /// <summary>
        /// Gets or sets a value indicating whether this <see cref="Workflow"/> is linked.
        /// </summary>
        /// <value><c>true</c> if linked; otherwise, <c>false</c>.</value>
        public bool Linked { get; set; }

        /// <summary>
        /// Gets or sets the linked connection.
        /// </summary>
        /// <value>The linked connection.</value>
        public TridentConnection LinkedConnection { get; set; }

        /// <summary>
        /// Gets or sets the activities.
        /// </summary>
        /// <value>The activities.</value>
        public List<WorkflowActivity> Activities { get; set; }

        /// <summary>
        /// Gets or sets the parameters.
        /// </summary>
        /// <value>The parameters.</value>
        public List<WorkflowParameter> Parameters { get; set; } 

        /// <summary>
        /// Gets the string id.
        /// </summary>
        /// <value>The string id.</value>
        [XmlIgnore]
        [DoNotClone]
        [DoNotCompare]
        public string StringId
        {
            get
            {
                return this.Id.ToString();
            }
        }

        /// <summary>
        /// Gets the activity parameters.
        /// </summary>
        /// <param name="activityName">Name of the activity.</param>
        /// <returns>ParametersCollection</returns>
        public List<WorkflowParameter> GetActivityParameters(string activityName)
        {
            List<WorkflowParameter> results = new List<WorkflowParameter>();
            foreach (WorkflowParameter param in this.Parameters)
            {
                if (param.BelongsToActivity.CompareIgnoreCase(activityName))
                {
                    results.Add(param);
                }
            }

            return results;
        }      
    }
}
